package com.example.fruitdemo.ruslet;

import com.example.fruitdemo.util.Code;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

@Data
public class R<T> {
    Integer code;
    T data;
    String msg;

    public static <T> R<T> Ok(T obj){
        R<T> r=new R<>();
        r.code= Code.OK_CODE;
        r.data=obj;
        return r;
    }
    //成功自定义设置code
    public static <T> R<T> Ok(int code){
        R<T> r=new R<>();
        r.code=code;
        return r;
    }
    public static <T> R<T> Ok(T obj,String msg){
        R<T> r=new R<>();
        r.code=Code.OK_CODE;
        r.data=obj;
        r.msg=msg;
        return r;
    }
    public static <T> R<T> Err(String msg){
        R<T> r=new R<>();
        r.code=Code.ERR_CODE;
        r.msg=msg;
        return r;
    }

    public static <T> R<T> Err(T obj){
        R<T> r=new R<>();
        r.code=Code.ERR_CODE;
        r.data=obj;
        return r;
    }
    public static R Ok(){
        R r=new R();
        r.code=Code.OK_CODE;
        return r;
    }

}
